package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("images")
public class ImageController {



    @PostMapping
    public Map upload(MultipartFile file ){




       HashMap<String, Object> map = new HashMap<>();
        //把图片传到指定的路径
        try {
            //String url = UploadUtil.upload(file, UploadUtil.Path + "/upload");
            String url = UploadUtil.uploadALiYun(file);
            map.put("status",1);
            map.put("url",url);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("status",0);
            map.put("url","上传失败");
        }
        return map;






    }

}
